<html>
<head><meta charset="utf-8"><title>chunks for Vec · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html">chunks for Vec</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="207410414"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207410414" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> traxys <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207410414">(Aug 19 2020 at 13:53)</a>:</h4>
<p>I wanted to do some <code>chunks</code> of a <code>Vec&lt;T&gt;</code> but saw that we had no methods for that, only <code>std::slice</code> has does, and I needed specifically a <code>Vec</code>, my type was not <code>Clone</code>.</p>
<p>I think that it is quite similiar to how <code>std::slice</code> can be <code>split</code>, but you can do that too with owned values in <code>Vec</code>, I'd like to know if there is any reason we could not have some kind of <code>vec_chunks</code> on <code>Vec</code> that consumes the Vec ? (If there is no reason apart "nobody coded that" I'l gladly do it !)</p>



<a name="207411346"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207411346" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207411346">(Aug 19 2020 at 14:00)</a>:</h4>
<p>there's is no technical reason I can think of, but each returned vec would have to be a newly allocated vec, if you care about that part of it.</p>



<a name="207411418"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207411418" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207411418">(Aug 19 2020 at 14:00)</a>:</h4>
<p>hm, it seems like with const generics if you're able to specify N at compile-time we could do Iterator::chunks which has Item = [T; N]</p>



<a name="207411444"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207411444" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207411444">(Aug 19 2020 at 14:00)</a>:</h4>
<p>maybe that's what we should actually do instead of the array_chunks method that was recently unstably added...</p>



<a name="207411620"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207411620" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207411620">(Aug 19 2020 at 14:02)</a>:</h4>
<p>I don't think adding <code>vec_chunks</code> is the best solution here.</p>
<p>IMO it would be a good idea to add <code>Iterator::chunks</code> now that const generics is usable</p>



<a name="207411662"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207411662" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207411662">(Aug 19 2020 at 14:02)</a>:</h4>
<p>which returns the content of an iterator in <code>N</code> element chunks</p>



<a name="207411737"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207411737" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Poliorcetics <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207411737">(Aug 19 2020 at 14:03)</a>:</h4>
<p>With a length in 0..=N elements for the last chunk I suppose</p>



<a name="207411784"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207411784" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> traxys <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207411784">(Aug 19 2020 at 14:03)</a>:</h4>
<p>Yeah I agree that Iterator::chunks would be the best, I was very conservative on only mirroring what <code>std::slice</code> was doing</p>



<a name="207411786"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207411786" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207411786">(Aug 19 2020 at 14:03)</a>:</h4>
<p>it has to be an exact iterator, you can't return a partial array</p>



<a name="207411804"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207411804" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207411804">(Aug 19 2020 at 14:03)</a>:</h4>
<p>yeah, probably with a method to consume the iter and return the final elements or something</p>



<a name="207411895"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207411895" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> traxys <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207411895">(Aug 19 2020 at 14:04)</a>:</h4>
<p>That is what <code>chunks_exact</code> does on slices yes</p>



<a name="207411989"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207411989" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207411989">(Aug 19 2020 at 14:05)</a>:</h4>
<p>It's slightly more difficult here as we have to return a owned array</p>



<a name="207412036"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207412036" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207412036">(Aug 19 2020 at 14:05)</a>:</h4>
<p>and we don't have a nice way to support partially filled arrays in std</p>



<a name="207412085"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207412085" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> traxys <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207412085">(Aug 19 2020 at 14:05)</a>:</h4>
<p>Yeah I don't see how you would be able to know how many remains, the easiest way would be to allocate a Vec for the remaining</p>



<a name="207412099"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207412099" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207412099">(Aug 19 2020 at 14:05)</a>:</h4>
<p>it does seem like the ideal is probably an arrayvec type</p>



<a name="207412202"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207412202" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> traxys <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207412202">(Aug 19 2020 at 14:06)</a>:</h4>
<p>And about the allocations, that's already what <code>split_off</code> does on Vec, where slice::split* does only slice manipulations</p>



<a name="207412294"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207412294" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> traxys <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207412294">(Aug 19 2020 at 14:07)</a>:</h4>
<p>I personnaly expect methods specific to vec that return elements in the front to allocate in some way</p>



<a name="207412319"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207412319" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207412319">(Aug 19 2020 at 14:07)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116122">simulacrum</span> <a href="#narrow/stream/122651-general/topic/chunks.20for.20Vec/near/207412099">said</a>:</p>
<blockquote>
<p>it does seem like the ideal is probably an arrayvec type</p>
</blockquote>
<p>hmm yeah, I am not sure if we want that as part of std though, as it will remain fairly obscure. It might make more sense to convert the remaining elements into <code>array::IntoIter</code> and return that</p>



<a name="207412365"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207412365" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207412365">(Aug 19 2020 at 14:07)</a>:</h4>
<p>I mean array::IntoIter is like 85% of a arrayvec type :)</p>



<a name="207412429"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207412429" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207412429">(Aug 19 2020 at 14:08)</a>:</h4>
<p>true <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span></p>



<a name="207412436"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207412436" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207412436">(Aug 19 2020 at 14:08)</a>:</h4>
<p>but yes that seems fine</p>



<a name="207412622"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207412622" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> traxys <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207412622">(Aug 19 2020 at 14:09)</a>:</h4>
<p>So in conclusion it would be better to wait for const generics than to add a specific version for Vec ?</p>



<a name="207412735"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207412735" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207412735">(Aug 19 2020 at 14:10)</a>:</h4>
<p>Const generics already works and can (probably) be used to implement this</p>



<a name="207412814"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207412814" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207412814">(Aug 19 2020 at 14:11)</a>:</h4>
<p>I personally think so, yes</p>
<p>I want to stabilize <code>min_const_generics</code> before the 2021 edition so I don't even think that stabilizing a method on <code>Vec</code> will necessarily be faster than waiting for const generics here</p>



<a name="207412949"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207412949" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207412949">(Aug 19 2020 at 14:12)</a>:</h4>
<p>I don't think we want to stabilize something that needs to allocate every chunk separately anyway</p>



<a name="207412979"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207412979" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207412979">(Aug 19 2020 at 14:12)</a>:</h4>
<p>I would be interested in a chunks_exact on Iterator</p>



<a name="207413027"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207413027" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207413027">(Aug 19 2020 at 14:13)</a>:</h4>
<p>naming choices: we already have <code>array_chunks</code>, so I think we probably want to stick with that name here</p>



<a name="207413071"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207413071" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207413071">(Aug 19 2020 at 14:13)</a>:</h4>
<p>hm, we only chose that due to conflict with existing chunks_exact, right?</p>



<a name="207413086"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207413086" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207413086">(Aug 19 2020 at 14:13)</a>:</h4>
<p>I originally wanted to just use <code>iter.chunks</code> but I think that's confusing, so <code>array_chunks</code> is probably better for consistency</p>



<a name="207413241"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207413241" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207413241">(Aug 19 2020 at 14:14)</a>:</h4>
<p>hm <span aria-label="shrug" class="emoji emoji-1f937" role="img" title="shrug">:shrug:</span> I find chunks_exact to not be too confusing, but I want the functionality more than the name :)</p>



<a name="207413247"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207413247" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207413247">(Aug 19 2020 at 14:14)</a>:</h4>
<p>i think <code>array_chunks</code> is more consistent here</p>



<a name="207413354"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207413354" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207413354">(Aug 19 2020 at 14:15)</a>:</h4>
<p>well my point is that we'd then deprecate and remove array::array_chunks</p>



<a name="207413393"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207413393" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207413393">(Aug 19 2020 at 14:15)</a>:</h4>
<p>with into_iter on arrays it becomes useless</p>



<a name="207413564"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207413564" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207413564">(Aug 19 2020 at 14:17)</a>:</h4>
<p>so we're not really being consistent with anything</p>



<a name="207414052"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207414052" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> traxys <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207414052">(Aug 19 2020 at 14:21)</a>:</h4>
<p>You would have to do some <code>MaybeUninit</code> to implement that right ? because you have no way of knowing when the iterator is going to finish ?<br>
So for the remainder you would detect would had not filled the array, but what would you do ? you would pass that half-init array and the number of init elements to a custom Iterator impl ?</p>



<a name="207414274"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207414274" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207414274">(Aug 19 2020 at 14:23)</a>:</h4>
<p>The remainder could probably converted to <code>array::IntoIter</code> and then used this way</p>



<a name="207414299"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207414299" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207414299">(Aug 19 2020 at 14:23)</a>:</h4>
<p>at least that's what I think is the best way</p>



<a name="207414468"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207414468" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207414468">(Aug 19 2020 at 14:24)</a>:</h4>
<blockquote>
<p>well my point is that we'd then deprecate and remove array::array_chunks</p>
</blockquote>
<p>that's true, we could just use <code>arr.iter().chunked</code> for this and <code>arr.iter_mut().chunked</code> and remove <code>array_chunks</code></p>



<a name="207414530"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207414530" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207414530">(Aug 19 2020 at 14:25)</a>:</h4>
<p>As long as we don't get worse codegen from that this seems fine to me</p>



<a name="207414666"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207414666" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207414666">(Aug 19 2020 at 14:26)</a>:</h4>
<p><code>array_chunks</code> does have the advantage of allowing the user to access the remainder right from the start while <code>iter::Chunked</code> will only allow that once it is finished</p>



<a name="207414726"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207414726" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207414726">(Aug 19 2020 at 14:26)</a>:</h4>
<p>also, how deal <code>DoubleEndedIterator</code> work with <code>iter::Chunked</code>?</p>



<a name="207414819"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207414819" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207414819">(Aug 19 2020 at 14:27)</a>:</h4>
<p>we can have an impl for <code>ArrayChunks&lt;[T; N]&gt;</code> or something that provides slice and <code>into_rest() -&gt; array::IntoIter&lt;[T; N]&gt;</code> access to the remainder</p>



<a name="207414890"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207414890" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207414890">(Aug 19 2020 at 14:28)</a>:</h4>
<p>not sure I follow, double ended iteration seems like it should work fine?</p>



<a name="207414914"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207414914" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207414914">(Aug 19 2020 at 14:28)</a>:</h4>
<p>obviously you might end up with "remainder" being the middle or so</p>



<a name="207415220"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207415220" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> traxys <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207415220">(Aug 19 2020 at 14:30)</a>:</h4>
<p>How would the <code>into_rest() -&gt; array::IntoIter&lt;[T; N]&gt;</code> work if you have more than <code>N</code> elements remaining ?</p>



<a name="207415431"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207415431" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207415431">(Aug 19 2020 at 14:32)</a>:</h4>
<p>I would expect it to return an empty iterator</p>



<a name="207415457"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207415457" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207415457">(Aug 19 2020 at 14:32)</a>:</h4>
<p>would be nice to check that <code>into_rest</code> is only called once the iterator is empty as part of the typesystem</p>



<a name="207415495"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207415495" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207415495">(Aug 19 2020 at 14:33)</a>:</h4>
<p>but I don't think that's easily possible</p>



<a name="207415519"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207415519" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> traxys <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207415519">(Aug 19 2020 at 14:33)</a>:</h4>
<p>(for double iteration i'd say too the remainder should be in the middle,  though should inside a chunk for backwards order or not for back access ?)</p>



<a name="207415551"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207415551" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> traxys <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207415551">(Aug 19 2020 at 14:33)</a>:</h4>
<p>You can return Option&lt;....&gt; to signify that ?</p>



<a name="207415625"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207415625" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207415625">(Aug 19 2020 at 14:34)</a>:</h4>
<p><span class="user-mention silent" data-user-id="237671">traxys</span> <a href="#narrow/stream/122651-general/topic/chunks.20for.20Vec/near/207415519">said</a>:</p>
<blockquote>
<p>(for double iteration i'd say too the remainder should be in the middle,  though should inside a chunk for backwards order or not for back access ?)</p>
</blockquote>
<p>not sure what you mean here</p>



<a name="207415683"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207415683" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207415683">(Aug 19 2020 at 14:34)</a>:</h4>
<p>I think it would make the most sense to fill up the internal array "backwards" when using <code>next_back</code></p>



<a name="207415758"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207415758" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> traxys <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207415758">(Aug 19 2020 at 14:35)</a>:</h4>
<p>If you access the iterator from the back, say element <code>n</code> then <code>n-1</code> then <code>n-2</code> would you return<br>
<code>[n, n-1, n-2, ...]</code> or <code>[n-k, n-(k+1), ... n -1, n]</code></p>



<a name="207415798"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207415798" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207415798">(Aug 19 2020 at 14:35)</a>:</h4>
<p>I think <code>[n-k, n-(k+1), ... n -1, n]</code> is the "correct" choice here</p>



<a name="207415929"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207415929" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> traxys <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207415929">(Aug 19 2020 at 14:36)</a>:</h4>
<p>I think it's the least confusing yeah, but people would still asks themselves what is it I'd think</p>



<a name="207418661"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207418661" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207418661">(Aug 19 2020 at 14:58)</a>:</h4>
<p><span class="user-mention" data-user-id="216206">@lcnr</span> into_rest would consume the iterator, surely?</p>



<a name="207418708"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207418708" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207418708">(Aug 19 2020 at 14:59)</a>:</h4>
<p>alternatively we'd have something like next_partial_chunk that gives you a (potentially) partial chunk, and always works</p>



<a name="207419232"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207419232" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207419232">(Aug 19 2020 at 15:03)</a>:</h4>
<blockquote>
<p>@lcnr into_rest would consume the iterator, surely?</p>
</blockquote>
<p>yeah I would expected it to</p>



<a name="207422894"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207422894" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207422894">(Aug 19 2020 at 15:29)</a>:</h4>
<p>Remainder can return a slice of the partial array, as a custom method can be borrowed (unlike <code>Iterator::next</code>). But this would only make sense once you've seen <code>None</code> to have read that far, unless we say that remainder also reads to end like last.</p>



<a name="207423567"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207423567" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207423567">(Aug 19 2020 at 15:34)</a>:</h4>
<p>I don't think <code>Iterator::chunks</code> is a replacement for <code>slice::array_chunks</code> though, as they're very different for borrowing</p>



<a name="207423753"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207423753" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207423753">(Aug 19 2020 at 15:36)</a>:</h4>
<p>e.g. <code>[&amp;T; 1_000_000]</code> vs <code>&amp;[T; 1_000_000]</code></p>



<a name="207432129"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207432129" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207432129">(Aug 19 2020 at 16:46)</a>:</h4>
<p><span class="user-mention" data-user-id="138448">@cuviper</span> hm, that is an interesting point</p>



<a name="207432321"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207432321" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207432321">(Aug 19 2020 at 16:48)</a>:</h4>
<p>hm actually I wonder, it seems like it would be valid to convert between those two types via ptr::read of each element, basically, right?</p>



<a name="207432376"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207432376" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207432376">(Aug 19 2020 at 16:48)</a>:</h4>
<p>either way we'd need attached/streaming iterators so doesn't matter I guess</p>



<a name="207432574"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207432574" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207432574">(Aug 19 2020 at 16:50)</a>:</h4>
<p>right, an <code>Iterator</code> adaptor can't invent an array reference, but <code>StreamingIterator</code> could</p>



<a name="207432585"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207432585" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207432585">(Aug 19 2020 at 16:50)</a>:</h4>
<p>I'm not sure how you mean to use <code>ptr::read</code></p>



<a name="207432886"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207432886" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207432886">(Aug 19 2020 at 16:52)</a>:</h4>
<p>FWIW, there's also <code>Itertools::chunks</code>, but that's a complicated beast with lazy grouping</p>



<a name="207432925"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207432925" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207432925">(Aug 19 2020 at 16:53)</a>:</h4>
<p><code>Itertools::tuples</code> is closer to what we want here</p>



<a name="207433000"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207433000" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207433000">(Aug 19 2020 at 16:53)</a>:</h4>
<p>(with homogenous tuples as a weak substitute for const-generic arrays)</p>



<a name="207433702"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207433702" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207433702">(Aug 19 2020 at 16:59)</a>:</h4>
<p>I mean that I <em>think</em> it is plausibly valid to go from <code>[&amp;T; N]</code> to <code>&amp;[T; N]</code>, copying out each element</p>



<a name="207433814"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207433814" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207433814">(Aug 19 2020 at 17:00)</a>:</h4>
<p>Probably won't optimize away, but I've been surprised before</p>



<a name="207433862"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207433862" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207433862">(Aug 19 2020 at 17:00)</a>:</h4>
<p>for <code>T: Copy</code>?</p>



<a name="207434224"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207434224" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207434224">(Aug 19 2020 at 17:03)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116122">simulacrum</span> <a href="#narrow/stream/122651-general/topic/chunks.20for.20Vec/near/207433702">said</a>:</p>
<blockquote>
<p>I mean that I <em>think</em> it is plausibly valid to go from <code>[&amp;T; N]</code> to <code>&amp;[T; N]</code>, copying out each element</p>
</blockquote>
<p>I also thought so, but this breaks with interior mutability, doesn't it?</p>



<a name="207440861"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207440861" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207440861">(Aug 19 2020 at 17:59)</a>:</h4>
<p><span class="user-mention" data-user-id="216206">@lcnr</span> how so?</p>



<a name="207440893"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207440893" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207440893">(Aug 19 2020 at 17:59)</a>:</h4>
<p><span class="user-mention" data-user-id="138448">@cuviper</span> no, in general. for T: Copy it is obviously true</p>



<a name="207441057"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207441057" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207441057">(Aug 19 2020 at 18:01)</a>:</h4>
<p>for <span class="user-mention" data-user-id="216206">@lcnr</span>'s point, I guess you need <code>T: Freeze</code></p>



<a name="207441157"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207441157" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207441157">(Aug 19 2020 at 18:01)</a>:</h4>
<p>If you have <code>[Cell&lt;u8&gt;] </code> and use <code>iter.chunks()</code> for this you have <code>[&amp;Cell(a)]</code> if you now copy this cell into a temporary array you have <code>&amp;[Cell(b)]</code>. We now mutate this copy. At this point the  original <code>Cell</code> still has the old value</p>



<a name="207441346"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207441346" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207441346">(Aug 19 2020 at 18:03)</a>:</h4>
<p>Right, and <code>Freeze</code> would exclude that type, but this is an internal-only trait</p>



<a name="207441360"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207441360" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207441360">(Aug 19 2020 at 18:03)</a>:</h4>
<p>Yeah</p>



<a name="207441380"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207441380" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207441380">(Aug 19 2020 at 18:03)</a>:</h4>
<p>I also think that this is dangerous with <code>Unpin</code> types</p>



<a name="207441434"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207441434" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207441434">(Aug 19 2020 at 18:03)</a>:</h4>
<p>as we could have a <code>Pin&lt;&amp;[UnpinTy]&gt;</code> which we can iterate over</p>



<a name="207441509"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207441509" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207441509">(Aug 19 2020 at 18:04)</a>:</h4>
<p>and then create a new copy of <code>UnpinTy</code> with a different address which is unsound</p>



<a name="207441519"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207441519" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207441519">(Aug 19 2020 at 18:04)</a>:</h4>
<p>aha, yeah, that's a good point</p>



<a name="207449231"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207449231" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207449231">(Aug 19 2020 at 19:10)</a>:</h4>
<p>doesn't this also mess up the lifetime? who owns that array?</p>



<a name="207449487"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207449487" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207449487">(Aug 19 2020 at 19:13)</a>:</h4>
<p>if you copy out the element, you need at least <code>T: Clone</code>, even if in unsafe code, because the source <code>&amp;T</code>'s could be referenced elsewhere</p>



<a name="207449721"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207449721" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207449721">(Aug 19 2020 at 19:15)</a>:</h4>
<p>that's why the array is referenced. Beyond pin and unsafecell this transform afaik is sound</p>



<a name="207449775"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207449775" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207449775">(Aug 19 2020 at 19:15)</a>:</h4>
<p>well, "who owns the array" is still an issue for <code>Iterator</code></p>



<a name="207449934"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207449934" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207449934">(Aug 19 2020 at 19:17)</a>:</h4>
<p>I guess you'd transform independently, but you have to deal with that <code>[&amp;T; N]</code> value on your stack</p>



<a name="207449989"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207449989" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207449989">(Aug 19 2020 at 19:17)</a>:</h4>
<p>It sounds like you are creating a new array by copying <code>T</code>'s from different places to be all adjacent. This will be a local variable, and if your function's return type is <code>&amp;[T; N]</code> then you can't return it</p>



<a name="207450114"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207450114" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207450114">(Aug 19 2020 at 19:18)</a>:</h4>
<p>yes, you'd need to stash it in a field of the struct. it's not insurmountable but definitely poses challenges</p>



<a name="207450144"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207450144" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207450144">(Aug 19 2020 at 19:18)</a>:</h4>
<p>to me, this all says that <code>Iterator::chunks</code> and <code>slice::array_chunks</code> should co-exist</p>



<a name="207450160"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207450160" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207450160">(Aug 19 2020 at 19:18)</a>:</h4>
<p>that seems right, given this consideration</p>



<a name="207450202"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207450202" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207450202">(Aug 19 2020 at 19:19)</a>:</h4>
<p>I'm still not exactly clear on what the type signature of <code>array_chunks</code> is</p>



<a name="207450206"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207450206" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> traxys <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207450206">(Aug 19 2020 at 19:19)</a>:</h4>
<p>Well all this references would deny the usefullness of the method I'd say, as it won't return owned values</p>



<a name="207450242"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207450242" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207450242">(Aug 19 2020 at 19:19)</a>:</h4>
<p>Iterator::chunks would have <code>Item = [T; N]</code> which is definitely useful</p>



<a name="207450259"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207450259" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207450259">(Aug 19 2020 at 19:19)</a>:</h4>
<p><a href="https://doc.rust-lang.org/nightly/std/primitive.slice.html#method.array_chunks">https://doc.rust-lang.org/nightly/std/primitive.slice.html#method.array_chunks</a></p>



<a name="207450309"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207450309" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> traxys <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207450309">(Aug 19 2020 at 19:20)</a>:</h4>
<p>Ok, I had not understood</p>



<a name="207450368"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207450368" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207450368">(Aug 19 2020 at 19:20)</a>:</h4>
<p>oh, this already exists? Which is the new one?</p>



<a name="207450376"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207450376" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207450376">(Aug 19 2020 at 19:20)</a>:</h4>
<p>If we keep <code>slice::aray_chunks</code> I again prefer <code>array_chunks</code> as the name for the iterator <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span></p>



<a name="207450380"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207450380" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207450380">(Aug 19 2020 at 19:20)</a>:</h4>
<p>the benefit of array_chunks is that even by-reference iteration gives you <code>&amp;[T; N]</code> rather than <code>[&amp;T; N]</code></p>



<a name="207450405"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207450405" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207450405">(Aug 19 2020 at 19:20)</a>:</h4>
<p>yeah naming is <span aria-label="shrug" class="emoji emoji-1f937" role="img" title="shrug">:shrug:</span> on my side :)</p>



<a name="207450415"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207450415" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207450415">(Aug 19 2020 at 19:20)</a>:</h4>
<p>We want to add <code>Iterator::chunks_name_not_yet_finalized</code></p>



<a name="207450434"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207450434" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> traxys <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207450434">(Aug 19 2020 at 19:21)</a>:</h4>
<p>I'm really bad at naming</p>



<a name="207450481"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207450481" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207450481">(Aug 19 2020 at 19:21)</a>:</h4>
<p>then let's just go with array_chunks <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span></p>



<a name="207450654"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207450654" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> traxys <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207450654">(Aug 19 2020 at 19:23)</a>:</h4>
<p>Why wouldn't we like <code>Iterator::chunks</code> ?</p>



<a name="207450709"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207450709" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207450709">(Aug 19 2020 at 19:23)</a>:</h4>
<p>my concern is that both <code>slice::chunks</code> and <code>slice::array_chunks</code> already exist</p>



<a name="207450730"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207450730" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207450730">(Aug 19 2020 at 19:23)</a>:</h4>
<p>and this method would be a lot more similar to <code>array_chunks</code></p>



<a name="207450829"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207450829" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207450829">(Aug 19 2020 at 19:24)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/122651-general/topic/chunks.20for.20Vec/near/207415457">said</a>:</p>
<blockquote>
<p>would be nice to check that <code>into_rest</code> is only called once the iterator is empty as part of the typesystem</p>
</blockquote>
<p>aside: I see that <code>ArrayChunks::remainder</code> also says something along these lines. Why would this be desirable? What if you stop iterating early and want the remainder of the vector?</p>



<a name="207450833"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207450833" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> traxys <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207450833">(Aug 19 2020 at 19:24)</a>:</h4>
<p>I feel that most people don't know <code>array_chunks</code> where they would intutively understand <code>chunks</code></p>



<a name="207450867"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207450867" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> traxys <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207450867">(Aug 19 2020 at 19:24)</a>:</h4>
<p>That would need allocations</p>



<a name="207450870"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207450870" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207450870">(Aug 19 2020 at 19:24)</a>:</h4>
<p>it would also be polite not to create a collision with <code>Itertools::chunks</code></p>



<a name="207450880"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207450880" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> traxys <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207450880">(Aug 19 2020 at 19:24)</a>:</h4>
<p>Yeah true</p>



<a name="207450910"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207450910" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207450910">(Aug 19 2020 at 19:25)</a>:</h4>
<p>yeah, array_chunks seems all around fine -- it'll still show up in search and whatnot.</p>
<p>Note that this will not need allocation</p>



<a name="207451002"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207451002" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> traxys <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207451002">(Aug 19 2020 at 19:25)</a>:</h4>
<p>We need allocations if we want to return remainder if <code>remainder.len() &gt; N</code></p>



<a name="207451062"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207451062" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207451062">(Aug 19 2020 at 19:26)</a>:</h4>
<p>but it's still in the original allocation</p>



<a name="207451124"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207451124" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207451124">(Aug 19 2020 at 19:27)</a>:</h4>
<p>yeah we probably wouldn't ever support that, it'd be a pain because the impl must be in core not alloc and then you don't have vec etc</p>



<a name="207451182"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207451182" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207451182">(Aug 19 2020 at 19:27)</a>:</h4>
<p><code>slice::array_chunks</code>, at least, operates on a slice. I don't see how it is any different from repeated <code>split_at</code></p>



<a name="207451189"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207451189" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207451189">(Aug 19 2020 at 19:27)</a>:</h4>
<p>but we can of course provide something like <code>Result&lt;Remainder&lt;T, N&gt;, impl Iterator&lt;Item = T&gt;&gt;</code></p>



<a name="207451206"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207451206" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> traxys <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207451206">(Aug 19 2020 at 19:27)</a>:</h4>
<p>Ah but we are not talking about <code>Vec</code> anymore</p>



<a name="207451207"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207451207" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207451207">(Aug 19 2020 at 19:27)</a>:</h4>
<p><span class="user-mention" data-user-id="271719">@Mario Carneiro</span> it returns arrays, rather than slices</p>



<a name="207451259"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207451259" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207451259">(Aug 19 2020 at 19:28)</a>:</h4>
<p>there are two possibilities for "remainder"</p>
<ul>
<li>we read &lt;N items at the end, so here they are</li>
<li>you want whatever the internal iterator has left, could be &gt;N</li>
</ul>



<a name="207451326"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207451326" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> traxys <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207451326">(Aug 19 2020 at 19:28)</a>:</h4>
<p>We are talking about a generic <code>Iterator::array_chunk</code> that coalesces items from an Iterator into <code>[T; N]</code></p>



<a name="207451350"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207451350" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> traxys <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207451350">(Aug 19 2020 at 19:28)</a>:</h4>
<p>Yeah the second is easy to support, just give back the wrapped iterator</p>



<a name="207451355"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207451355" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207451355">(Aug 19 2020 at 19:28)</a>:</h4>
<p>well yes, you need unsafe magic to make that coercion work, so I see why <code>array_chunks</code> exists from a type signature point of view. But If you do repeated <code>split_at</code> then it is easy to support a "remainder" function returning whatever is left of the original slice</p>



<a name="207451436"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207451436" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207451436">(Aug 19 2020 at 19:29)</a>:</h4>
<p><code>split_at</code> is a slice thing, not for generic <code>Iterator</code>, so let's keep that separate</p>



<a name="207451451"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207451451" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207451451">(Aug 19 2020 at 19:29)</a>:</h4>
<p>aha, so that's what's new here</p>



<a name="207451461"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207451461" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207451461">(Aug 19 2020 at 19:30)</a>:</h4>
<p>(<code>slice::array_chunks</code> does the remainder already)</p>



<a name="207451683"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207451683" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207451683">(Aug 19 2020 at 19:31)</a>:</h4>
<p>If you are working over a <code>Vec</code>, then you don't have to do any gathering</p>



<a name="207451855"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207451855" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> traxys <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207451855">(Aug 19 2020 at 19:33)</a>:</h4>
<p>For supporting the first i'd say some function along the lines of <code>Self::remainder(self) -&gt; Result&lt;array::IntoIter, Self&gt;</code>, that returns <code>Err(self)</code> if the iter has not yet finished, and <code>array::IntoIter</code> if it has finished</p>



<a name="207451898"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207451898" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207451898">(Aug 19 2020 at 19:33)</a>:</h4>
<p>so you could have an iterator over the vec that does repeated <code>split_at_mut</code> from an <code>OwningRef&lt;Box&lt;[T]&gt;, [T]&gt;</code> to get a non-allocating vec version of <code>slice::array_chunks</code></p>



<a name="207451983"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207451983" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> traxys <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207451983">(Aug 19 2020 at 19:34)</a>:</h4>
<p>Maybe not a <code>Result</code>, more something like <code>enum Remainder { Finished(....), NotFinshed(...)}</code></p>



<a name="207452057"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207452057" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207452057">(Aug 19 2020 at 19:34)</a>:</h4>
<p>It's a much different conversation if we're only doing this on <code>Vec</code> and/or owned arrays as the source</p>



<a name="207452210"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207452210" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> traxys <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207452210">(Aug 19 2020 at 19:36)</a>:</h4>
<p>I agree, but according to <span class="user-mention" data-user-id="216206">@lcnr</span>  we can do it for <code>Iterator</code> with const-generics, and I agree that it's much better to have a generic impl than the one with Vec</p>



<a name="207452319"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207452319" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> traxys <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207452319">(Aug 19 2020 at 19:37)</a>:</h4>
<p>(By that I mean it will be as long to stabilize the generic impl as the Vec one)</p>



<a name="207452373"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207452373" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207452373">(Aug 19 2020 at 19:37)</a>:</h4>
<p>(sorry to be slow to the point) Regarding the version that polls an <code>Iterator&lt;Item=T&gt;</code> to return <code>[T; N]</code>, won't this be pretty move-heavy? <code>[T; N]</code> is a big type to wrap in an option</p>



<a name="207452457"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207452457" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207452457">(Aug 19 2020 at 19:38)</a>:</h4>
<p>I'm in favor of doing something for all <code>Iterator</code></p>



<a name="207452501"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207452501" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207452501">(Aug 19 2020 at 19:38)</a>:</h4>
<p><span class="user-mention" data-user-id="271719">@Mario Carneiro</span> you have the same "big type" consideration if you've moving arrays from a <code>Vec</code> too</p>



<a name="207452566"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207452566" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207452566">(Aug 19 2020 at 19:39)</a>:</h4>
<p>indeed, I don't know how these functions could ever be used well. You just have to hope they get optimized away</p>



<a name="207452588"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207452588" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207452588">(Aug 19 2020 at 19:39)</a>:</h4>
<p>just don't use them for big <code>N</code></p>



<a name="207452730"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207452730" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207452730">(Aug 19 2020 at 19:41)</a>:</h4>
<p>I would probably use this in places where I currently use <code>Itertools::tuples</code>, which only goes up to 4 anyway</p>



<a name="207452787"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207452787" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> traxys <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207452787">(Aug 19 2020 at 19:41)</a>:</h4>
<p>We could provide both an array version and a <code>Box&lt;[T]&gt;</code> version though ?</p>



<a name="207452855"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207452855" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> traxys <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207452855">(Aug 19 2020 at 19:42)</a>:</h4>
<p>For cases where you have big <code>T</code> or chunk_size ?</p>



<a name="207452884"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207452884" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> traxys <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207452884">(Aug 19 2020 at 19:42)</a>:</h4>
<p>(Where the Boxed would need quite a lot of allocations, but it's your choice)</p>



<a name="207452894"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207452894" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207452894">(Aug 19 2020 at 19:42)</a>:</h4>
<p>or <code>Box&lt;[T; N]&gt;</code>, sure if you're willing to allocate for each</p>



<a name="207453071"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207453071" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207453071">(Aug 19 2020 at 19:44)</a>:</h4>
<p>that's only possible from <code>Vec</code> though -- array and <code>Iterator</code> are defined in <code>core</code></p>



<a name="207453165"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207453165" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207453165">(Aug 19 2020 at 19:45)</a>:</h4>
<p><span class="user-mention silent" data-user-id="138448">cuviper</span> <a href="#narrow/stream/122651-general/topic/chunks.20for.20Vec/near/207453071">said</a>:</p>
<blockquote>
<p>that's only possible from <code>Vec</code> though -- array and <code>Iterator</code> are defined in <code>core</code></p>
</blockquote>
<p>std is special, so while we can't do this for iterator we can implement stuff for arrays in std</p>



<a name="207453208"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207453208" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207453208">(Aug 19 2020 at 19:45)</a>:</h4>
<p><em>array is defined in the compiler not in core</em></p>



<a name="207453489"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207453489" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207453489">(Aug 19 2020 at 19:48)</a>:</h4>
<p>true, there could be an <code>array_alloc</code> lang item, like the existing <code>slice_alloc</code></p>



<a name="207456608"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207456608" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> traxys <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207456608">(Aug 19 2020 at 20:15)</a>:</h4>
<p>If people are intersted, here is what could an impl look like: <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=af8bef8b27fdc701a2ac55712ea4965e">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=af8bef8b27fdc701a2ac55712ea4965e</a></p>



<a name="207458483"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207458483" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207458483">(Aug 19 2020 at 20:33)</a>:</h4>
<p>Why did you use <code>transmute_copy</code> + <code>forget</code> instead of <code>transmute</code>?</p>



<a name="207458649"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207458649" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207458649">(Aug 19 2020 at 20:34)</a>:</h4>
<p>You should be able to do this with only one bit-copy from <code>buffer</code> to the return slot</p>



<a name="207458684"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207458684" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> jknodt <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207458684">(Aug 19 2020 at 20:35)</a>:</h4>
<p><code>transmute</code> isn't supported for <code>[MaybeUninit&lt;T&gt;; N] -&gt; [T; N]</code> yet, so any case where <code>transmute</code> would make sense has to have <code>transmute_copy</code> for now</p>



<a name="207458777"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207458777" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207458777">(Aug 19 2020 at 20:36)</a>:</h4>
<p>I thought <code>transmute</code> could handle any types?</p>



<a name="207458891"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207458891" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207458891">(Aug 19 2020 at 20:38)</a>:</h4>
<p>oh, I see, it's a rustc implementation issue</p>



<a name="207458957"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207458957" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207458957">(Aug 19 2020 at 20:38)</a>:</h4>
<p>is it possible to just call <code>memcpy</code> directly?</p>



<a name="207459003"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207459003" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207459003">(Aug 19 2020 at 20:39)</a>:</h4>
<p><code>transmute_copy</code> will do that</p>



<a name="207459018"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207459018" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207459018">(Aug 19 2020 at 20:39)</a>:</h4>
<p>or is the point that as long as you write <code>transmute_copy</code> llvm can pick up on the pattern</p>



<a name="207498758"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/chunks%20for%20Vec/near/207498758" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> traxys <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/chunks.20for.20Vec.html#207498758">(Aug 20 2020 at 08:15)</a>:</h4>
<p>I stole that idea from the <code>array::IntoIter::new</code> impl but it's more expensive that that, because it will be called repeatedly. Maybe the copy will be optimized away ?</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>